package gov.pbc.nn.core.bdf.security;

import java.io.IOException;

import org.springframework.security.web.context.HttpRequestResponseHolder;
import org.springframework.stereotype.Component;

import com.bstek.bdf2.core.exception.IExceptionHandler;
import com.bstek.dorado.core.Configure;

@Component
public class SSOLoginExceptionHandler implements IExceptionHandler {

	@Override
	public void handle(HttpRequestResponseHolder requestResponseHolder, Throwable exception) {
		try {
			requestResponseHolder.getResponse().sendRedirect(Configure.getString("bdf2.formLoginUrl"));
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	@Override
	public boolean support(Throwable exception) {
		return exception instanceof SSOLoginException;
	}

}
